<head>
 <style type="text/css"> 
        input.number { text-align:right; }
 </style>

</head>
<script type="text/javascript" charset="utf-8">
	$(function() {
		$('#dialog-form').load('<?php echo site_url(); ?>anggota/popup');
		$("#dialog-form").dialog({
			autoOpen: false,
			title: 'Anggota',
			height: 400,
			width: 712,
			modal: true,
			buttons: {
				'OK': function() {
					var chkIdx = $('input:radio:checked').val();
					var aData = popup_table.fnGetData(chkIdx);
					$("#anggotaID").val($("#id"+chkIdx).val());
					$("#anggota").val(aData[0]);
					$("#nama_anggota").val(aData[1]);
					$("#alamat_anggota").val(aData[2]);
					$("#pekerjaan_anggota").val(aData[3]);
					$(this).dialog('close');
				},
				'Batal': function() {
					$(this).dialog('close');
				}
			},
		});

		$('#anggota').focus(function() {
				$('#dialog-form').dialog('open');
			});

	});
	
	$(document).ready(function() {
	  $.viewMap = {
		'0' : $([]),
		'view1' : $('#view1'),
		'view2' : $('#view2a, #view2b'),
		'view3' : $('#view3')
	  };

	  $('#viewSelector').change(function() {
		// hide all
		$.each($.viewMap, function() { this.hide(); });
		// show current
		$.viewMap[$(this).val()].show();
	  }).change();
	});

</script>

<div class="post-title"><h2><a href="<?php echo current_url();?>"><?php echo $title; ?></a></h2></div>

<div class="post-body">

<div id="dialog-form"></div>

<?php
	echo form_open('simpanan/'.$form_act, 'id="simpanan_form"');

	echo "<div id='error' class='error-message' ";

	if($this->session->userdata('ERRMSG_ARR'))
	{
		echo ">";
		echo $this->session->userdata('ERRMSG_ARR');
		$this->session->unset_userdata('ERRMSG_ARR');
	}
	else
	{
		echo "style='display:none'>";
	}
	
	echo "</div>";

	$data['class'] = 'input';
	if ($act == 'view') $data['disabled'] = TRUE;
?>
	
	<table width="300" border="0" align="center" cellpadding="2" cellspacing="0">						  
		
		<tr>
			<th><?php echo form_label('Rek Simpanan **','no_rekening'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'no_rekening';
					
					$data_kode = '510';
					$data_bln = date("m");
					$data_thn = date("y");
					$data_id = '0001';
					
					if($act=='add')
					{ 
						if($new_id == ''){						
							//$data['value'] = 'SP00001';
							$data['value'] = $data_kode.'.'.$data_bln.'.'.$data_thn.'.'.$data_id;
						}else{						
							//$data['value'] = 'SP' . formatIdsimpanan(substr($new_id->no_rekening, 2) + 1);
							//echo substr($new_id->no_rekening,7,2).substr($new_id->no_rekening,4,2).'<'.$data_thn.$data_bln;
							if ((substr($new_id->no_rekening,7,2).substr($new_id->no_rekening,4,2)) < ($data_thn.$data_bln) ) {
								$data_id = '0001';
							}else{						
								$data_id = formatIdsimpanan(substr($new_id->no_rekening,10) + 1);
							}
							$data['value'] = $data_kode.'.'.$data_bln.'.'.$data_thn.'.'.$data_id;
						}						
					}else{
						$data['value'] = (set_value('no_rekening')) ? set_value('no_rekening') : $simpanan_data['no_rekening'];
					}
					
					$data['title'] = "no rekening tidak boleh kosong";
					//echo form_input($data);
					echo "<input id='no_rekening' name='no_rekening' size='20' class='required' value='$data[value]' />";
				?>
			</td>			
		</tr>
		<tr>
			<th colspan='2'>** format : 510-mm-yy-no urut </th>			
		</tr>
		<tr>
			<th><?php echo form_label('Tanggal Reg','tgl_reg'); ?></th>
			<td>
				<?php 
					$data['name'] = 'tgl_reg';
					//$data['id'] = 'datepicker2';
					if($act=='add')
					{ 
						$data['value'] = date("Y-m-d");;
					}else{					
						$data['value'] = (set_value('tgl_reg')) ? set_value('tgl_reg') : $simpanan_data['tgl_reg'];
					}
					$data['title'] = "Tanggal harus diisi dengan format dddd-mm-yy";				
					//echo form_input($data);
					echo "<input id='datepicker2' name='tgl_reg' size='15' class='required' value='$data[value]' />";
				?>
			</td>	
			
		</tr>		
		<tr>
			<th><?php echo form_label('ID Anggota *','anggota'); ?></th>
			<td>
				<?php 
					//echo form_hidden('anggotaID',$simpanan_data['anggota_id']);

					$data['name'] = $data['id'] = 'anggota';
					$data['value'] = (set_value('anggota')) ? set_value('anggota') : $simpanan_data['anggota_id'];
					$data['title'] = "Anggota tidak boleh kosong";
					//echo form_input($data);
					echo "<input id='anggota' name='anggota' size='25' class='required' value='$data[value]' />";
				?>
			</td>
		</tr>
		<tr>
			<th><?php echo form_label('Nama','nama_anggota'); ?></th>
			<td>
				<?php 
					/*
					echo form_hidden('anggotaID',$simpanan_data['anggota_id']);
				
					$data['name'] = $data['id'] = 'anggota';
					$data['value'] = (set_value('anggota')) ? set_value('anggota') : $simpanan_data['nama_anggota'];
					$data['title'] = "Anggota tidak boleh kosong";
					*/
					
					$data['name'] = $data['id'] = 'nama_anggota';
					$data['value'] = (set_value('nama_anggota')) ? set_value('nama_anggota') : $simpanan_data['nama_anggota'];
					
					echo "<input id='nama_anggota' name='nama_anggota' size='25' class='required' value='$data[value]' disabled='1'/>";
				?>
			</td>				
		</tr>		
		<tr>
			<th><?php echo form_label('Biaya Administrasi *','biaya'); ?></th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'biaya';
					$data['value'] = (set_value('biaya')) ? set_value('biaya') : $simpanan_data['biaya'];
					$data['title'] = "Perkiraan biaya harus diisi angka";
										
					if($act=='add')
					{ 
						$data['value'] = 0;
						?>
						<input type=text id='biaya' name='biaya' size='20' value='Rp0,00' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value);' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20'>
						
						<?php
					}else{					
						$data['value'] = (set_value('biaya')) ? set_value('biaya') : $simpanan_data['biaya'];
						?>
						<input type=text id='biaya' name='biaya' size='20' value='<?php echo 'Rp'.number_format(($data['value']), 0, '', '.') . ',00'; ?>' align=right onkeypress='return numbersonly(this, event)' onBlur='this.value=formatIDR(this.value);' class='required' onClick='this.value=unFormatIDR(this.value);' maxlength='20'>
						<?php
						
					}
					
					//echo "<input align='right' id='biaya' name='biaya' size='50' class='required number' value='$data[value]' />";
				?>
				
			</td>	
		</tr>
		
		<tr>
			<th>
				<?php echo form_label('Keterangan','keterangan'); ?>
			</th>
			<td>
				<?php 
					$data['name'] = $data['id'] = 'keterangan';
					$data['value'] = (set_value('keterangan')) ? set_value('keterangan') : $simpanan_data['keterangan'];
					unset($data['title']);
					echo "<input id='keterangan' name='keterangan' size='50' value='$data[value]' />";	
				?>
			</td>			
		</tr>		
			
	</table>
	
	<div class="buttons">
		<?php 
			if($act!='view')
			{ 
				echo form_submit('simpan','Simpan', "id = 'button-save'" );
				echo form_reset('reset','Reset', "id = 'button-reset'" );
				echo form_button(array('id' => 'button-cancel', 'content' => 'Batal', 'onClick' => "location.href='".site_url()."simpanan'" ));
			}
			else
			{
				echo form_button(array('id' => 'button-cancel', 'content' => 'Kembali', 'onClick' => "location.href='".site_url()."simpanan'" ));
			}
		?>				
	</div>
	
<?php echo form_close(); ?>

</div>

<script type='text/javascript'>
	//Validasi di client
		
	$(document).ready(function(){
		$("#simpanan_form").validate({
			messages: {
					biaya: " Biaya harus diisi"
			}
		});
    });
</script>
<?php
	function formatIdsimpanan($id){
		if (strlen($id) == 1)
		{
			return '000' . $id;
		}
		else if (strlen($id) == 2)
		{
			return '00' . $id;
		}
		else if (strlen($id) == 3)
		{
			return '0' . $id;
		}else {
			return $id;
		}
	}
?>